<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>修改--个人资料</title>
<link rel="stylesheet" href="${ctx }/resources/layui/css/layui.css" media="all" />
<link rel="stylesheet" href="${ctx }/resources/css/public.css" media="all" />
<link rel="stylesheet" href="${ctx }/resources/zTree/css/metroStyle/metroStyle.css" type="text/css">
<link rel="stylesheet" type="text/css" href="${ctx }/resources/plugin/css/index.css">
</head>
<body class="childrenBody">
	<form class="layui-form" action="#" id="frm" method="post" lay-filter="frm">
		<div class="layui-col-md3 layui-col-xs12 user_right">
		<div class="layui-upload-list">
			<img class="layui-upload-img layui-circle userFaceBtn userAvatar" src="${user.imgpath }" id="userFace">
		</div>
		<button type="button" class="layui-btn layui-btn-primary userFaceBtn" id="userpath"><i class="layui-icon">&#xe67c;</i> 掐指一算，我要换一个头像了</button>
		<span id="userText"></span>
		<input type="hidden" name="imgpath" id="imgpath" value="${user.imgpath }">
		<input type="hidden" name="id" value="${user.id }">
	</div>
	<div class="layui-col-md6 layui-col-xs12">
		<div class="layui-form-item">
			<label class="layui-form-label">用户名</label>
			<div class="layui-input-block">
				<input type="text" value="${user.loginname }" disabled class="layui-input layui-disabled">
			</div>
		</div>
		<div class="layui-form-item">
			<label class="layui-form-label">真实姓名</label>
			<div class="layui-input-block">
				<input type="text" value="${user.name }" placeholder="请输入真实姓名" lay-verify="required" class="layui-input realName">
			</div>
		</div>
		<!-- <div class="layui-form-item" pane="">
			<label class="layui-form-label">性别</label>
			<div class="layui-input-block userSex">
				<input type="radio" name="sex" value="男" title="男" checked="">
				<input type="radio" name="sex" value="女" title="女">
				<input type="radio" name="sex" value="保密" title="保密">
			</div>
		</div> -->
	
		<div class="layui-form-item">
			<div class="layui-input-block" style="text-align: center;">
				<!--lay-submit标记当按钮是一个提交按钮   -->
				<a href="javascript:void(0)" class="layui-btn" lay-submit=""  lay-filter="userSubmit">提交</a>
				<button type="reset" class="layui-btn layui-btn-primary">重置</button>
			</div>
		</div>
	</form>
</body>
<script type="text/javascript" src="${ctx }/resources/layui/layui.js"></script>
<script type="text/javascript" src="${ctx }/resources/zTree/js/jquery-1.4.4.min.js"></script>
<script type="text/javascript" src="${ctx }/resources/zTree/js/jquery.ztree.core.js"></script>
<script type="text/javascript" src="${ctx }/resources/plugin/js/selectTree.js"></script>
<script type="text/javascript">
layui.use([ 'form','jquery','layer','upload' ], function() {
	var form=layui.form;//得到form对象
	var $=layui.jquery;
	var upload = layui.upload;
	var layer = parent.layer === undefined ? layui.layer : parent.layer;
	//修改提交事件
	form.on("submit(userSubmit)",function(data){
		var params=$("#frm").serialize();
		$.post("${ctx}/user/updateUser.action?"+params,function(obj){
			layer.msg(obj.msg);
			parent.tableIns.reload();//刷新表格
			//关闭窗口
			/* var index=layer.getFrameIndex(window.name);
			layer.close(index); */
		}) 
	});
	
	
	//普通图片上传
	var uploadInst = upload
			.render({
				elem : '#userpath',
				url : '${ctx}/upload/uploadFile.action',
				accept:'images',
				acceptMime:'image/*',
				field:'mf',
				before : function(obj) {
					//预读本地文件示例，不支持ie8
					obj.preview(function(index, file,
							result) {
						$('#userFace').attr('src', result); //图片链接（base64）
					});
				},
				done : function(res) {
					//如果上传失败
					if (res.code > 0) {
						return layer.msg('上传失败');
					}
					//上传成功
					$('#userFace').attr('src', res.data.src); //图片链接（base64）
					$('#imgpath').val(res.data.src);
				},
				error : function() {
					//演示失败状态，并实现重传
					var userText = $('#userText');
					userText.html('<span style="color: #FF5722;">上传失败</span> <a class="layui-btn layui-btn-xs user-reload">重试</a>');
					userText.find('.user-reload').on(
							'click', function() {
								uploadInst.upload();
							});
				}
			});
	
});	
	

</script>
</html>